package Chapter8;

//172页程序8.8

import java.awt.*;
import javax.swing.*;

class MyWindow extends JFrame { //创建子类的形式 GridLayout布局管理器
    private JButton b1, b2, b3, b4, b5, b6;
    MyWindow() {
        setTitle("GridLayout布局管理器测试程序");
        Container contentPane = getContentPane();
        contentPane.setPreferredSize(new Dimension(400, 300)); //new Dimension设置长方形区域为窗口大小
        contentPane.setLayout(new GridLayout(3, 2)); //三行两列
        b1 = new JButton("布局1"); //先行后列的填入按钮
        b2 = new JButton("布局2");
        b3 = new JButton("布局3");
        b4 = new JButton("布局4");
        b5 = new JButton("布局5");
        b6 = new JButton("布局6");
        contentPane.add(b1);
        contentPane.add(b2);
        contentPane.add(b3);
        contentPane.add(b4);
        contentPane.add(b5);
        contentPane.add(b6);
        pack();
        setVisible(true);
    }
}

public class GridLayoutDemo {
    public static void main(String[] args) {
        MyWindow that = new MyWindow();
        that.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}